package com.jky.stmall.exercise;

import com.jky.stmall.exercise.BaseInterface;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxy {
    //获取动态代理的对象
    public static BaseInterface getProxy(BaseInterface bi){
         BaseInterface b = (BaseInterface) Proxy.newProxyInstance(
                 BaseInterface.class.getClassLoader(),
                 new Class[]{BaseInterface.class},
                 new InvocationHandler() {
                     @Override
                     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                         Object obj=method.invoke(bi,args);
                         return null;
                     }
                 }
         );
         return b;
    }
}
